<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
		<style>
			[v-cloak]{
				display: none;
			}
			.yellow {
				background: yellow;
			}
			#app div {
				width: 300px;
				height: 300px;
				background: red;
				display: none;
			}
		</style>
		<script src="./src/vue.js"></script>
	</head>

	<body>
		<div id="app">
			<button 
				v-for="item,i in news" 
				:class="{yellow: i === showIndex}"
				class="fontSize"
				@click="tab(i)"
			>
				{{item.title}}
			</button>
			<div
				:style="styleFn(i)"
				v-for="item,i in news"
			>
				<p v-for="option in item.list">
					{{option.newsTitle}}
				</p>
			</div>
		</div>
		<script>
			
			let data = [
				{
					title: '新闻',
					list: [
						{
							newsTitle: '新闻版块1'
						},
						{
							newsTitle: '新闻版块2'
						},
						{
							newsTitle: '新闻版块3'
						}
					]
				},
				{
					title: '娱乐',
					list: [
						{
							newsTitle: '娱乐版块1'
						},
						{
							newsTitle: '娱乐版块2'
						},
						{
							newsTitle: '娱乐版块3'
						}
					]
				},
				{
					title: '体育',
					list: [
						{
							newsTitle: '体育版块1'
						},
						{
							newsTitle: '体育版块2'
						},
						{
							newsTitle: '体育版块3'
						}
					]
				}
			];

			new Vue({
				el: '#app',
				data: {
					news: data,
					showIndex:0  // 控制要显示的面板
				},
				methods: {
					tab (n) {
						this.showIndex = n;
					},
					styleFn(m){
						let display = this.showIndex === m ? 'block' : 'none';
						return {
								display: display
							    }
					}
				}
			})



		</script>
	</body>
</html>